<?php
/**
 * J2T RewardsPoint2
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@j2t-design.com so we can send you a copy immediately.
 *
 * @category   Magento extension
 * @package    RewardsPoint2
 * @copyright  Copyright (c) 2009 J2T DESIGN. (http://www.j2t-design.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Rewardpoints_Model_Mysql4_Rules_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    public function _construct()
    {
        parent::_construct();
        $this->_init('rewardpoints/rules');
    }


    public function setValidationFilter($websiteId, $now = null)
    {
        if (is_null($now)) {
            $now = Mage::getModel('core/date')->date('Y-m-d');
        }
 
        $this->getSelect()->where('rewardpoints_rule_activated=1');
        $this->getSelect()->where('find_in_set(?, website_ids)', (int)$websiteId);
        //$this->getSelect()->where('find_in_set(?, customer_group_ids)', (int)$customerGroupId);

        $this->getSelect()->where('rewardpoints_rule_start is null or rewardpoints_rule_start<=?', $now);
        $this->getSelect()->where('rewardpoints_rule_end is null or rewardpoints_rule_end>=?', $now);
        //$this->getSelect()->order('sort_order');

        return $this;

    }


}